package com.mxpio.erp.common.sales.entity;


import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mxpio.erp.common.jpa.model.Notice;
import com.mxpio.erp.common.jpa.model.NoticeLine;
import com.mxpio.erp.common.vo.OrderExcuteLineVo;
import com.mxpioframework.security.annotation.Dict;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(name = "MB_ERP_SALES_SN")
@Schema(description="发货通知单")
public class ShippingNotice extends Notice {

    private static final long serialVersionUID = 1L;

    @Column(name = "NOTICE_CREATE_TIME_")
    @Schema(description = "单据日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date noticeCreateTime;

    @Column(name = "NOTICE_TYPE_")
    @Schema(description = "单据类型")
    @Dict(dicCode="ERP_SALES_SHIPPING_NOTICE_TYPE")
    private String noticeType;

    @Column(name = "PN_NAME_")
    @Schema(description = "客户名称")
    private String pnName;

    @Column(name = "ADDRESS_")
	@Schema(description = "收货地址")
	private String address;

	@Column(name = "CONSIGNEE_")
	@Schema(description = "收货人")
	private String consignee;

	@Column(name = "ADDR_TEL_")
	@Schema(description = "联系电话")
	private String addrTel;

    @Column(name = "SHIPPING_WAY_")
    @Schema(description = "发货方式")
    private String shippingWay;

    @Column(name = "FREIGHT_WAY_")
    @Schema(description = "运费方式")
    private String freightWay;

    @Column(name = "BILLING_")
    @Schema(description = "是否开票")
    @Dict(dicCode = "ERP_COMMON_YESNO")
    private Boolean billing;

    @Column(name = "TAX_RATE_")
    @Schema(description = "税率")
    private BigDecimal taxRate;

    @Column(name = "REVIEWER_")
    @Schema(description = "审核人")
    private String reviewer;

    @Column(name = "REVIEW_TIME_")
    @Schema(description = "审核时间")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date reviewTime;

    @Column(name = "MEMO_")
    @Schema(description = "备注")
    private String memo;

    @Transient
    private List<ShippingNoticeLine> shippingNoticeLines;

    @Transient
    private SalesOrder salesOrder;
    @Override
    public String initTypeCode() {
        return "SN1";
    }


	@Override
	public NoticeLine createLine(OrderExcuteLineVo orderExcuteVo) {
		NoticeLine noticeLine = new ShippingNoticeLine();
		noticeLine.setOriginBizLineNo(orderExcuteVo.getBizOrderlineNo());
		noticeLine.setOriginBizNo(orderExcuteVo.getBizOrderNo());
		noticeLine.setItemCode(orderExcuteVo.getItemCode());
		noticeLine.setNoticeNo(this.getNoticeNo());
		noticeLine.setQuantity(orderExcuteVo.getQuantity());
		noticeLine.setSort(orderExcuteVo.getSort());
		noticeLine.setLotNo(orderExcuteVo.getLotNo());
        noticeLine.setSubLotIndex(orderExcuteVo.getSubLotIndex());
		return noticeLine;
	}


	@Override
	public List<? extends NoticeLine> getNoticeLines() {
		return this.shippingNoticeLines;
	}
}
